import request from '@/router/axios';

/**
 * 根据菜单id获取子菜单
 * @param {String} parentId 父级菜单id
 * @param {Object} params   其他查询条件
 */
export const getLazyList = (parentId, params) => {
  return request({
    url: '/system/menu/lazy-list',
    method: 'get',
    params: {
      ...params,
      parentId
    }
  })
}

/**
 * 菜单完整树结构
 */
export const getMenuTree = () => {
  return request({
    url: '/system/menu/tree',
    method: 'get',
  })
}

export const remove = (ids) => {
  return request({
    url: '/system/menu/remove',
    method: 'post',
    params: {
      ids,
    }
  })
}

export const add = (row) => {
  return request({
    url: '/system/menu/submit',
    method: 'post',
    data: row
  })
}

export const update = (row) => {
  return request({
    url: '/system/menu/submit',
    method: 'post',
    data: row,
  })
}

// 获取详情
export const getMenu = (id) => {
  return request({
    url: '/system/menu/detail',
    method: 'get',
    params: {
      id,
    }
  })
}

// 顶部菜单（暂时没用）
export const getTopMenu = () => request({
  url: '/system/menu/top-menu',
  method: 'get'
});

// 左侧导航菜单
export const getRoutes = (topMenuId) => request({
  url: '/system/menu/routes',
  method: 'get',
  params: {
    topMenuId,
  }
});
